/*
  Copyright (C) 2011, Kyungjoo Kim
  
  This file is part of UHM (Unassembled HyperMatrix) sparse direct solver.
  
  All rights reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  Also add information on how to contact you by electronic and paper mail.
  
  
  Kyungjoo Kim
  iamkyungjoo@gmail.com
*/
#include "uhm/common.hxx"
#include "uhm/const.hxx"
#include "uhm/util.hxx"

#include "uhm/object.hxx"

#include "uhm/operation/scheduler.hxx"
#include "uhm/operation/element.hxx"

#include "uhm/mesh/node.hxx"
#include "uhm/mesh/element.hxx"

#include "uhm/matrix/uhm/matrix.hxx"

#include "uhm/mesh/mesh.hxx"

namespace uhm {
  // --------------------------------------------------------------
  // ** Front interface
  void Mesh_::solve_1() { this->solve_1( this->get_decomposition_method() ); }
  void Mesh_::solve_1( int decomposition ) {
    switch (decomposition) {
    case UHM_CHOL:         this->solve_chol_1();         break;
    case UHM_CHOL_PIV:     
    case UHM_CHOL_INCPIV:  this->solve_chol_piv_1();     break;
    case UHM_LDL_NOPIV:    this->solve_ldl_nopiv_1();    break;
    case UHM_LDL_PIV:      
    case UHM_LDL_INCPIV:   this->solve_ldl_piv_1();      break;
    case UHM_LU_NOPIV:     this->solve_lu_nopiv_1();     break;
    case UHM_LU_PIV:       
    case UHM_LU_INCPIV:    this->solve_lu_piv_1();       break;
    case UHM_QR:           this->solve_qr_1();           break;
    default:
      printf("wrong method\n");
      abort();
    }
  }
  
  void Mesh_::solve_2() { this->solve_2( this->get_decomposition_method() ); }
  void Mesh_::solve_2( int decomposition ) {
    switch (decomposition) {
    case UHM_CHOL:         this->solve_chol_2();         break;
    case UHM_CHOL_PIV:     
    case UHM_CHOL_INCPIV:  this->solve_chol_piv_2();     break;
    case UHM_LDL_NOPIV:    this->solve_ldl_nopiv_2();    break;
    case UHM_LDL_PIV:      
    case UHM_LDL_INCPIV:   this->solve_ldl_piv_2();      break;
    case UHM_LU_NOPIV:     this->solve_lu_nopiv_2();     break;
    case UHM_LU_PIV:       
    case UHM_LU_INCPIV:    this->solve_lu_piv_2();       break;
    case UHM_QR:           this->solve_qr_2();           break;
    default:
      printf("wrong method\n");
      abort();
    }
  }

  void Mesh_::solve() { this->solve( this->get_decomposition_method() ); }
  void Mesh_::solve( int decomposition ) {
    this->solve_1(decomposition);
    this->solve_2(decomposition);
  }

}
